package main

import (
	"fmt"
	"net/http"
)

type TraceHandler struct {
	h http.Handler
}

func (r TraceHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	println("get", req.URL.Path, "from", req.RemoteAddr)
	r.h.ServeHTTP(w, req)
}

// IndexHandler "/"
func IndexHandler(w http.ResponseWriter, req *http.Request) {
	fmt.Fprint(w, "hello go 2")
}

func main() {
	http.HandleFunc("/", IndexHandler)

	h := http.FileServer(http.Dir("../"))
	http.Handle("/files", TraceHandler{h})

	err := http.ListenAndServe("127.0.0.1:8088", nil)
	if err != nil {
		panic(err)
	}
}
